{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](process.svg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造请求地址\n",
    "userName = 'yangjh'\n",
    "repoName = 'sda-2020-2'\n",
    "url = f'https://gitee.com/api/v5/repos/{userName}/{repoName}/commits?page=1&per_page=100'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 发送请求\n",
    "import requests\n",
    "\n",
    "response = requests.get(url)\n",
    "# print(type(response.json()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas\n",
    "df = pandas.DataFrame(data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'author': {'name': 'yangjh',\n",
       "  'date': '2021-10-26T11:18:29+08:00',\n",
       "  'email': 'yangjh@yeah.net'},\n",
       " 'committer': {'name': 'yangjh',\n",
       "  'date': '2021-10-26T11:18:29+08:00',\n",
       "  'email': 'yangjh@yeah.net'},\n",
       " 'message': '变量计数案例\\n',\n",
       " 'tree': {'sha': '8548c4211c7c8036dda98a65f8ad26bcf27653e2',\n",
       "  'url': 'https://gitee.com/api/v5/repos/yangjh/sda-2020-2/git/trees/8548c4211c7c8036dda98a65f8ad26bcf27653e2'}}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[1,\"commit\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getCommitDate(commit):\n",
    "  return commit['author']['date']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 拿到每次推送的日期信息字符串\n",
    "df['commitDate'] = df['commit'].apply(getCommitDate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "datestr = '2021-09-28T15:53:47+08:00'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 将字符串转化为日期\n",
    "from datetime import datetime\n",
    "def getcounts(str):\n",
    "  d = datetime.fromisoformat(str)\n",
    "  return d.isocalendar()[1]-datetime(2021,8,30).isocalendar()[1]+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "getcounts('2021-11-01T00:05:23+04:00')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 计算所有推送的周次\n",
    "df['counts'] = df['commitDate'].apply(getcounts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(df['counts'].value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = df['counts'].value_counts().index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = df['counts'].value_counts().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<BarContainer object of 5 artists>"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAANFElEQVR4nO3df6idhX3H8c+niaLJXC16VlrT7PrHCBNh6g5ZWzthphatYmH0jwgWVjbuBrbTblDsX6X/dVBG98coXLStUI3YVGHYzUWo7Sa0aW9iuiZGh7XRJv2RI1tndWVR+9kf57maxBPPc+157vO9975fcMm9OSeXD5fknXOf+5zzOIkAAHW9pe8BAIA3RqgBoDhCDQDFEWoAKI5QA0BxG7v4pBdeeGHm5ua6+NQAsCbt27fvuSSDSbd1Euq5uTktLi528akBYE2y/cyZbuPQBwAUR6gBoDhCDQDFEWoAKI5QA0BxhBoAimsVatufsH3I9kHbu2yf0/UwAMDY1FDbvkjSX0saJrlU0gZJO7seBgAYa3voY6Okc21vlLRJ0k+6mwQAONnUZyYmOWb7c5KelfQrSXuS7Dn9frbnJc1L0tatW9/0oLnbv/6m/2wXjnz2+r4nzBxfY5xJpb8b/L14TZtDH2+T9CFJF0t6p6TNtm8+/X5JFpIMkwwHg4lPVwcAvAltDn28X9KPkoySvCTpfknv7XYWAGBJm1A/K+ndtjfZtqQdkg53OwsAsGRqqJPslbRb0n5JP2j+zELHuwAAjVYvc5rk05I+3fEWAMAEPDMRAIoj1ABQHKEGgOIINQAUR6gBoDhCDQDFEWoAKI5QA0BxhBoAiiPUAFAcoQaA4gg1ABRHqAGgOEINAMURagAojlADQHFtLm67zfaBk96et33bCmwDAKjFFV6SPCnpMkmyvUHSMUkPdDsLALBkuYc+dkj6YZJnuhgDAHi95YZ6p6RdXQwBAEzWOtS2z5Z0o6SvnuH2eduLthdHo9Gs9gHAurecR9TXSdqf5OeTbkyykGSYZDgYDGazD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n/Lek/+950ujUVatsD2+c3758r6RpJT/Q6aookn0qyJcmcxt/ifiNJ6UchtjfbPm/pfUkf0PhbyLKS/EzSj21va35rh6THe5zU1k1aBYc9Gs9KerftTc0P9ndIOtzzpqls/07z61aNj0/f0++i15vZq+cV8Q5JdzU/JX+LpPuSrIrT3VaZt0t6YPxvURsl3ZPkoX4ntfJxSXc3hxOelvTRnve8oeY/wWsk/WXfW9pIstf2bkn7Jb0s6TEVf2p242u2L5D0kqRbKv6QeU2dngcAa9GaOvQBAGsRoQaA4gg1ABRHqAGgOEINAMURagAojlADQHH/D4iOIZG9QZpCAAAAAElFTkSuQmCC",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.bar(x,y)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
  },
  "kernelspec": {
   "display_name": "Python 3.9.1 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
